package day0728API.WebServer;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

//只写服务端(服务器软件)  (用浏览器当客户端)
public class StartServer {

    private ServerSocket serverSocket;
    StartServer(){
        try {//1.服务器创建ServerSocket对象，监听8088端口
            System.out.println("正在启动服务器");
            serverSocket=new ServerSocket(8088);
            System.out.println("服务器启动完毕");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private void start() {
        while(true){
            try {//2.调用accept方法等待客户端连接
                Socket s=serverSocket.accept();
                //3.一个客户端连接后立即创建一个ClientThread线程为此客户端服务
                // (一个线程服务一个客户端)
                ClientThread clientThread=new ClientThread(s);
                clientThread.start();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    public static void main(String[] args) {
        StartServer server= new StartServer();
        server.start();

    }


}
